<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
</head>
<body class="no-skin">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>

<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="col-sm-offset-2" style="margin-top: 100px;">
                <form:form commandName="TaskMainFilter" cssClass="form-horizontal" role="form"  onsubmit="return false;">
                    <div class="row">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right">
                                    任务名称
                                </label>
                                <div class="col-sm-8">
                                    <input type="text"  name="mainName"  placeholder="任务名称"  value="${TaskMainFilter.mainName}"
                                           class="form-control required">
                                </div>
                            </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right">
                                任务内容
                            </label>
                            <div class="col-sm-8">
                                <textarea type="text" name="content" placeholder="任务内容"
                                       class="form-control required" style="resize: vertical;min-height: 50px;height: 80px">${TaskMainFilter.content}</textarea>
                            </div>
                        </div>
                    </div>
                   <!-- <div class="row ">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right" for="categoryId">
                                <a style="color: red">*</a>事项类型
                            </label>
                            <div class="col-sm-8">
                                <select type="text" id="categoryId" name="categoryId" placeholder="事项类型" readonly value="${TaskMainFilter.categoryId}"
                                       class="form-control required">
<%--                                    <c:forEach items="${types}" var="type">--%>
<%--                                        <option value="${type.category}">${type.category}</option>--%>
<%--                                    </c:forEach>--%>
                                </select>
                            </div>
                        </div>
                    </div> -->
                 <%--   创建立项任务  督查组单位--%>
                    <input type="hidden" value="${inspectionId}"  name="inspectionId">
                    <%--   创建立项任务  督查组单位  委托给  单位完成立项任务--%>
                    <div class="row ">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right" >
                                委托单位
                            </label>
                            <!--multiple="true"-->
                            <div class="col-sm-8">
                                <select name=""  id="e1"  name="overdueDept" onchange="addHandle(this)">
                                    <option></option>
                                    <c:forEach items="${units}" var="unit">
                                        <option value="${unit.sysId}">${unit.deptName}</option>
                                    </c:forEach>
                                </select>
                                <input type="hidden" value=""  >
                            </div>
                        </div>
                    </div>
                    <div class="row" style="margin-top: 100px">
                        <div class="form-group">
                            <label class="col-sm-offset-1 col-sm-1 text-right control-label">任务附件</label>
                            <div class="col-sm-8 pos-rel">
                                <input type="file" class="form-control"  id="fileupload" style="display: none">
                                <input type="hidden" class="form-control1"  id="fileupload1" name="file" value="${TaskMainFilter.file}">
                                <button class="btn btn-info"  onclick="document.getElementById('fileupload').click()"><span class="glyphicon glyphicon-open"></span>上传附件</button>
                            </div>
                        </div>
                    </div>
                    <div class="row" style="margin-top: 100px">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right">
                            </label>
                            <div class="col-sm-6">
                                <input type="button" value="关闭" class="btn-sm btn-default pull-right" onclick="javascript: parent.close_current_app();" style="margin-left: 10px"/>
                                <input type="button" value="添加任务" class="btn-sm btn-info pull-right" onclick="handleAdd()"/>
                            </div>
                        </div>
                    </div>
                </form:form>
                </div>
            </div>
        </div>
    </div>
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<script type="text/javascript">
    $(document).ready(function () {
        $("#e1").select2({
            placeholder: "请输入或点击选择经办人",
            width: "100%",
            closeOnSelect: false,
            allowClear: true,
        });

        // $(".placeholder").select2({
        //     allowClear: true
        // });
    });
    function addHandle(data) {
        //$(data).siblings("input").val($(data).val());
        // $(data).siblings("input").val($(data).val().join(","));
    }

    function handleAdd() {
        var inspectionId = $("input[name='inspectionId']").val()
        var content = $("textarea[name='content']").val()
        var mainName = $("input[name='mainName']").val()
        //var overdueDept = $("input[name='overdueDept']").val()
        var file = $("#fileupload1").val()
        console.log(inspectionId,content,mainName,overdueDept)
        var postJosn = {"mainName":mainName,"content":content,"inspectionId":inspectionId,"file":file,"overdueDept":overdueDept}
        console.log(postJosn)
        return;
        $.post("/taskCrucial/inspection/create",postJosn,function (res) {
            if(res){
                if(res.code == '200'){
                    alert('添加成功')
                    setTimeout(function () {
                        parent.close_current_app();
                    },50)
                } else {
                    alert('添加失败')
                }
            }
        })
    }
    /**
     * 上传附件
     */
    $("#fileupload").bind('change',function () {
        var fileVal = $("#fileupload").val();
        if (fileVal == null || fileVal == "") {
            alert("未选择任何文件");
            return;
        }
        // 判断文件大小是否大于10M
        var fileSize = $("#fileupload")[0].files[0].size / 1024 / 1024;
        var formData = new FormData();
        formData.append("files", $("#fileupload")[0].files[0]);
        if (fileSize > 10) {
            alert("上传文件大小不能大于10M");
            return;
        }
        $(".shade").fadeIn(100);
        $(".warning").fadeIn(100);
        $('.la-square-jelly-box').show();
        showShade();
        //警告框自定义内容
        $('.warning>.title>em').html('加载中……');
        $.ajax({
            url: "/filesUpload/uploadBatch",
            data: formData,
            type: "post",
            async:false,
            processData: false,
            contentType: false,
            success: function(data) {
                var data = JSON.parse(data);
                // $("#fileupload").attr("sysid",data.data.sysid);
                $("#fileupload1").val(data.data.sysid);
                if (data.code === "200") {
                    $('.warning>.title>em').html('上传成功');
                    $(".shade").fadeOut(2000);
                    $(".warning").fadeOut(2000);
                } else {
                    $('.warning>.title>em').html('上传失败');
                }
            },
            error: function (data) {
                alert("附件上传失败 ！！请联系管理员");
            }
        });
    });

    function rightTipBOX(msg) {
        if(msg == undefined){
            msg = ''
        }
        $.gritter.add({
            title: "提示",
            text: msg
        });
    }
</script>
</body>
</html>
